package com.cnkvha.trackcontestmgmt;

import java.util.ArrayDeque;
import java.util.Deque;

public class LoggerThread extends Thread {

    private final Deque<String> q = new ArrayDeque<>();

    private boolean stop = false;

    @Override
    public void run() {
        while(!stop) {
            while(q.size() > 0) {
                System.out.println(q.poll());
            }
            try {
                Thread.sleep(10);
            } catch (InterruptedException e) {
                e.printStackTrace();
            }
        }
    }

    public void log(String text) {
        String t = "> " + text;
        q.add(t);
        TrackContestManagement.instance.getControlWindow().appendGUILog(t);
    }

    public void log(String text, Object... params) {
        String t = ">" + String.format(text, params);
        q.add(t);
        TrackContestManagement.instance.getControlWindow().appendGUILog(t);
    }
}
